﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;
using ExpertMIS.Entities;

namespace ExpertMIS.UserControl
{
    public partial class ucDomainAbstract : System.Web.UI.UserControl
    {
        private QuestionBroker _questionBroker = new QuestionBroker();

        private void RefreshDomain()
        {
            DomainBroker broker = new DomainBroker();
            
            dlColumns.DataSource = broker.GetRootDomain();
            dlColumns.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            RefreshDomain();
        }

        protected void dlColumns_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DomainEntity domain = e.Item.DataItem as DomainEntity;
                DataList dlQuestionList = e.Item.FindControl("dlQuestionList") as DataList;
                if (dlQuestionList != null && domain != null)
                {
                    dlQuestionList.DataSource = _questionBroker.GetDomainLastQuestion(domain.OID, 10);
                    dlQuestionList.DataBind();
                }
            }
        }
    }
}